using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_StockManage_StockInfoOut : Member, IRequiresSessionState
{
	protected Literal ltrTitle;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected TextBox txtSearchInfoNumber;
	protected DropDownList ddlStockStatus;
	protected Button btnSearch;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Panel pnlManage;
	protected Label lblStockNumber;
	protected Label lblInputTime;
	protected Label lblInputer;
	protected Label lblReceiptEndDate;
	protected Label lblBuyerName;
	protected Label lblPayTime;
	protected Label lblDeliver_TotalPrice;
	protected Label lblInvoice_TotalPrice;
	protected Label lblMoneyGoods;
	protected Label lblReceiptMoney;
	protected Label lblAreadyReceiptMoney;
	protected Label lblFee;
	protected Label lblStockStatus;
	protected Label lblRemarks;
	protected GridView gvItem;
	protected Panel pnlDetail;
	private string linkHead = "";
	private string beforeUrl = "StockInfoOut.aspx?1=1";
	private int infoOrderID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public int InfoOrderID
	{
		get
		{
			if (base.Request.QueryString["infoOrderID"] != null)
			{
				this.infoOrderID = Convert.ToInt32(base.Request.QueryString["infoOrderID"].Trim());
			}
			return this.infoOrderID;
		}
		set
		{
			this.infoOrderID = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerStockPower(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(base.ActionTabInfo);
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (DisplayName == "checkinfo")
			{
				this.pnlManage.Visible = false;
				this.pnlDetail.Visible = true;
				if (this.InfoOrderID > 0)
				{
					this.InitPage();
				}
				return;
			}
		}
		this.pnlManage.Visible = true;
		this.pnlDetail.Visible = false;
		this.BindData();
	}
	protected void InitPage()
	{
		string sql = "select o.BuyerName,DeliverStatus,MoneyGoods,Deliver_TotalPrice,Invoice_TotalPrice,sio.* from HLJXC_StockInfoOrder as sio,HLShop_Order as o where sio.OrderID=o.OrderFormID and sio.InfoOrderID=" + this.InfoOrderID;
		DataTable dataTable = this.conn.GetDataTable(sql);
		for (int i = 0; i < dataTable.Rows.Count; i++)
		{
			this.lblStockNumber.Text = dataTable.Rows[i]["InfoNumber"].ToString();
			this.lblInputTime.Text = dataTable.Rows[i]["CreateDate"].ToString();
			this.lblInputer.Text = dataTable.Rows[i]["Inputer"].ToString();
			this.lblReceiptEndDate.Text = dataTable.Rows[i]["ReceiptEndDate"].ToString();
			this.lblBuyerName.Text = dataTable.Rows[i]["BuyerName"].ToString();
			this.lblPayTime.Text = dataTable.Rows[i]["ReceiptDate"].ToString();
			this.lblDeliver_TotalPrice.Text = "0";
			if (dataTable.Rows[i]["Deliver_TotalPrice"] != DBNull.Value)
			{
				this.lblDeliver_TotalPrice.Text = dataTable.Rows[i]["Deliver_TotalPrice"].ToString();
			}
			this.lblInvoice_TotalPrice.Text = "0";
			if (dataTable.Rows[i]["Invoice_TotalPrice"] != DBNull.Value)
			{
				this.lblInvoice_TotalPrice.Text = dataTable.Rows[i]["Invoice_TotalPrice"].ToString();
			}
			this.lblMoneyGoods.Text = "0";
			if (dataTable.Rows[i]["MoneyGoods"] != DBNull.Value)
			{
				this.lblMoneyGoods.Text = dataTable.Rows[i]["MoneyGoods"].ToString();
			}
			this.lblReceiptMoney.Text = "0";
			if (dataTable.Rows[i]["ReceiptMoney"] != DBNull.Value)
			{
				this.lblReceiptMoney.Text = dataTable.Rows[i]["ReceiptMoney"].ToString();
			}
			this.lblAreadyReceiptMoney.Text = "0";
			if (dataTable.Rows[i]["AlreadyReceiptMoney"] != DBNull.Value)
			{
				this.lblAreadyReceiptMoney.Text = dataTable.Rows[i]["AlreadyReceiptMoney"].ToString();
			}
			this.lblFee.Text = "0";
			if (dataTable.Rows[i]["Fee"] != DBNull.Value)
			{
				this.lblFee.Text = dataTable.Rows[i]["Fee"].ToString();
			}
			this.lblStockStatus.Text = BLLInstance.BllStockInfoOrder.GetStockStatusStr(dataTable.Rows[i]["StockStatus"]);
			this.lblRemarks.Text = dataTable.Rows[i]["Remark"].ToString();
		}
		string sql2 = "select p.ProductID,p.ProductName,ProductSmallImageUrl,item.* from HLJXC_StockItemOrder as item,HLShop_Product as p where item.ProductID=p.ProductID and item.InfoOrderID=" + this.InfoOrderID;
		DataTable dataTable2 = this.conn.GetDataTable(sql2);
		this.gvItem.DataSource = dataTable2;
		this.gvItem.DataBind();
		for (int j = 0; j < this.gvItem.Rows.Count; j++)
		{
			string text = this.gvItem.Rows[j].Cells[2].Text;
			string text2 = this.gvItem.Rows[j].Cells[3].Text;
			if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2))
			{
				this.gvItem.Rows[j].Cells[5].Text = (Convert.ToInt32(text) * Convert.ToDecimal(text2)).ToString();
			}
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBeginDate.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and DATEDIFF(DD, StockDate,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchEndDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, StockDate,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("InfoNumber");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchInfoNumber.Text = text4;
		}
		else
		{
			text4 = this.txtSearchInfoNumber.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and InfoNumber like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&InfoNumber=" + text4;
		}
		string text5 = Fetch.Get("StockStatus");
		if (!string.IsNullOrEmpty(text5))
		{
			this.ddlStockStatus.ddlSelect(text5);
		}
		else
		{
			text5 = this.ddlStockStatus.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text5))
		{
			text = text + " and StockStatus=" + text5;
			this.linkHead = this.linkHead + "&StockStatus=" + text5;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "order by sio.InfoOrderID desc";
		string value = this.txtSearchBeginDate.Text.Trim();
		string value2 = this.txtSearchEndDate.Text.Trim();
		if (!string.IsNullOrEmpty(value) || !string.IsNullOrEmpty(value2))
		{
			result = "order by StockDate desc";
		}
		return result;
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HLJXC_StockInfoOrder as sio,HLShop_Order as o where sio.OrderID=o.OrderFormID and StockOrderType='outSell' and o.SalerID=" + base.user.UserID + " ";
		int pageSize = this.gvManage.PageSize;
		int listCount = BLLInstance.BllClientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,o.OrderFormNum,o.BuyerName,MoneyGoods,Deliver_TotalPrice,Invoice_TotalPrice,sio.* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = BLLInstance.BllClientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, listCount, "条记录&nbsp;每页" + pageSize + "条记录&nbsp;", url);
	}
	public string GetStatusStr(object obj)
	{
		return BLLInstance.BllStockInfoOrder.GetStockStatusStrMark(obj);
	}
	protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindData();
	}
	protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
}
